home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 008 / graph.h < prev    next >
Text File  |  1985-06-03  |  6KB  |  169 lines

  1. /******************************************************************
  2.  *                                  *
  3.  *   GRAPH.H                              *
  4.  *                                  *
  5.  *   Max R. Dürsteler      Dec 1983                  *
  6.  *   12405 Village Square Terrace                  *
  7.  *   Rockville Md. 20852                      *
  8.  ******************************************************************
  9.  */
  10.  
  11. /* Constants */
  12.  
  13. /* IBM color code table */
  14. /* This table conforms to the colorcodes of the 6845 color register */
  15. /* in 16-color modes. Unfortunately, MSDOS2.0 is using another color code */
  16. /* table if using MSDOS graphics routines. */
  17. #define BLACK    0x0
  18. #define BLUE    0x1
  19. #define GREEN    0x2
  20. #define CYAN    0x3
  21. #define RED    0x4
  22. #define MAGENTA 0x5     /* MAGENTA */
  23. #define BROWN    0x6
  24. #define WHITE    0x7
  25. #define GRAY    0x8
  26. #define LBLUE    0x9     /* light blue */
  27. #define LGREEN    0xa
  28. #define LCYAN    0xb
  29. #define LRED    0xc
  30. #define LMAGENTA 0xd
  31. #define YELLOW    0xe
  32. #define LWHITE    0xf    /* high intensity white */
  33.  
  34. /* Color-select register */
  35. #define COLREG    0x3d9    /* Color-select register I/O adress */
  36. #define EMODREG 0x3dd    /* Extended mode/plane-select register I/O adress */
  37. #define EMRES    0x10    /* Extended medium resolution graphics mode */
  38. #define EHRES    0x20    /* Extended high resolution graphics mode */
  39. #define EALTPLN 0x40    /* Extended mode alternate plane (1: plane 1)*/
  40.  
  41.  
  42. /* TEXTMOD, MRESMOD, HRESMOD for use as input to */
  43. /* subroutine screen(mode) to set screen modes using BIOS video-IO */
  44. #define TEXTMOD 3    /* 25x80 color text mode */
  45. #define MRESMOD 4    /* 320x200 color graphics mode */
  46. #define HRESMOD 6    /* 640x320 graphics mode */
  47. #define EMRESMOD 12    /* extended 320x200 color graphics mode */
  48. #define EHRESMOD 14    /* extended 640x200 color graphics mode */
  49.  
  50. /* Flags for _graphflag */
  51. #define FILLOFF 00
  52. #define FILLON    01
  53.  
  54. /* Flagcodes for motion directions */
  55. #define XPLUS    001    /* right */
  56. #define XMINUS    002    /* left */
  57. #define YPLUS    004    /* up */
  58. #define YMINUS    010    /* down */
  59.  
  60. /* Codes for marker symbols */
  61. #define POINT     0    /* small dot */
  62. #define SQUARE     1    /* empty square */
  63. #define FSQUARE  2    /* filled square */
  64. #define DIAMOND  3    /* empty diamond */
  65. #define FDIAMOND 4    /* filled diamond */
  66. #define CROSS     5    /* cross */
  67. #define XCROSS     6    /* x */
  68. #define CERCLE     7    /* open circle */
  69. #define FCERCLE  8    /* filled circle */
  70. #define BSQUARE  9    /* big open square */
  71. #define BDIAMOND 10    /* big open diamond */
  72.  
  73. #define NSYMBOLS 11    /* Number of available symbol types */
  74.  
  75. /* definitions related to polygon drawing routines */
  76. #define MAXEDGES    50    /* Maximal number of polygon sides */
  77. #define SCANDECR     1    /* Size of scanline decrement */
  78.  
  79. /* list of actual polygon edges used by polygon filling routines */
  80. struct EDGE {
  81.     float ymax;        /* upper y coordinate: y-top */
  82.     float ymin;        /* lower y coordinate: y-bottom */
  83.     float xa;        /* x coordinate to ymax: x-top */
  84.     float dx;        /* inverse slope of side */
  85. };
  86.  
  87. /* screen definitions in pixels */
  88. struct FRAME {
  89.     float heightstart;/* starting column index of screen/frame */
  90.     float widthstart; /* starting row index of screen */
  91.     float heightend;  /* ending column index of screen */
  92.     float widthend;   /* ending row index of screen */
  93.     float height;      /* heigth of screen/frame in pixels */
  94.     float width;      /* width of screen/frame in pixels */
  95.     float charwidth;  /* width of current characters */
  96.     float charheight; /* height of current characters */
  97.     float trnx, trny; /* translation parameters */
  98.     float sclx, scly; /* scale parameters */
  99.     float angl;      /* rotation angle */
  100. };
  101.  
  102. /* character control variables in screen pixels */
  103. struct ICHARSPEC {
  104.     int icwidth ;         /* character width & height in pixels */
  105.     int icheight;         /* (default 8x8 matrix on IBM display */
  106.     int icdirflg;         /* character direction flag */
  107. };
  108.  
  109. /* character control variables for inpreter subroutines in pixels */
  110. /* Macros */
  111.  
  112. /* DOS Version 2.00 screen control sequences, textmode only */
  113. #define CLS "\033[2J\n" /* Erases whole screen, cursor goes home */
  114. #define cls() (printf(CLS))
  115. #define max(x,y)    ((x) >= (y) ? (x) : (y))
  116. #define min(x,y)    ((x) <= (y) ? (x) : (y))
  117.  
  118. /* Functions */
  119.  
  120. /* Assembler subroutines */
  121. extern _screen(), _dot(), clear();
  122. /* Screen initialisation */
  123. extern screen();
  124. /* Integer screen pixel graphics */
  125. extern dot(), doline(), dosymbol(), dochar();
  126. /* Floating point graphics in normalized coordinates */
  127. extern setcolor(), setbackg(), setsymbol(), setfill();
  128. extern setcharsize(), setchardir();
  129. extern moveabs2(), lineabs2(), markabs2(), polyabs2();
  130. extern markrel2(), moverel2(), linerel2(), polyrel2();
  131. extern text();
  132.  
  133. /* Pixel patterns of marker symbols (1x1 to 5x5 matrix) */
  134. char MARKER[NSYMBOLS][5] = {
  135.     { '\0', '\0', '\010', '\0', '\0'},              /* small dot */
  136.     { '\0', '\034', '\024', '\034', '\0'},          /* empty square */
  137.     { '\0', '\034', '\034', '\034', '\0'},          /* filled square */
  138.     { '\0', '\010', '\024', '\010', '\0'},          /* empty diamond */
  139.     { '\0', '\010', '\034', '\010', '\0'},          /* filled diamond */
  140.     { '\010', '\010', '\076', '\010', '\010'},      /* cross */
  141.     { '\0', '\024', '\010', '\024', '\0'},          /* x */
  142.     { '\034', '\042', '\042', '\042', '\034'},      /* open circle */
  143.     { '\034', '\076', '\076', '\076', '\034'},      /* filled circle */
  144.     { '\076', '\042', '\042', '\042', '\076'},      /* big open square */
  145.     { '\010', '\024', '\042', '\024', '\010'}};     /* big open diamond */
  146.  
  147. /* Graphic status registers /flags */
  148.  
  149. int _graphmode;       /* currrent graphic mode */
  150. int _graphflag;       /* flag register */
  151. int _colreg;          /* status of color-select register */
  152. int _color;          /* current color used */
  153. int _symbol;          /* current marker symbol */
  154. int _background;      /* current background color */
  155. int _ixold, _iyold;   /* coordinates of last point in pixels */
  156. float _xold, _yold;   /* coordinates of last point in relative coordinates */
  157.  
  158. struct FRAME display; /* current display parameters (set by screen())*/
  159. /* current display character parameters in pixels */
  160. struct ICHARSPEC icspec = {8, 8, YPLUS};
  161. struct EDGE pol[MAXEDGES] = {0.0};  /* polygon edge parameter list */
  162. double hmatrix[3][3] = {
  163.     { 1, 0, 0 },
  164.     { 0, 1, 0 },
  165.     { 0, 0, 1 }
  166. };
  167.  
  168. /* End of graphics include file graph.h */
  169.